#include "Resource.h"


ResourceMng* ResourceMng::_instance = NULL;


/**--------------------------------------------------------
*Description : Constructor
*Method name : ResourceMng
*Parameters :   
*Return value :
--------------------------------------------------------**/
ResourceMng::ResourceMng(LPDIRECT3DDEVICE9	D3ddv, LPDIRECT3DSURFACE9 BackBuffer)
{
	d3ddv = D3ddv;
	backBuffer = BackBuffer;
	//SURFACE, load hinh nen vao list vector
	
	/*_listSurface.push_back(new SURFACE(d3ddv, backBuffer, L"..\\Resources\\Images\\beachnoceanbgs.png"));
	_listSurface.push_back(new SURFACE(d3ddv, backBuffer, L"..\\Resources\\Images\\imgBgGame.png"));*/
	_listSurface.push_back(new SURFACE(d3ddv, backBuffer, L"..\\Resources\\Images\\background.jpg"));
	_listSurface.push_back(new SURFACE(d3ddv, backBuffer, L"..\\Resources\\Images\\Menu.jpg"));
	_listSurface.push_back(new SURFACE(d3ddv, backBuffer, L"..\\Resources\\Images\\About.jpg"));
	_listSurface.push_back(new SURFACE(d3ddv, backBuffer, L"..\\Resources\\Images\\transfermap.png"));
	_listSurface.push_back(new SURFACE(d3ddv, backBuffer, L"..\\Resources\\Images\\GameOver.jpg"));
	_listSurface.push_back(new SURFACE(d3ddv, backBuffer, L"..\\Resources\\Images\\GameWin.jpg"));
	
	
	
	
	//TEXTURE, load hinh nhan vat vao list vector
	/*_listTexture.push_back(new TEXTURE(L"kitty_left.bmp", 3, 2, 6, D3DCOLOR_XRGB(255, 255, 255)));
	_listTexture.push_back(new TEXTURE(L"kitty_right.bmp", 3, 2, 6, D3DCOLOR_XRGB(255, 255, 255)));
	_listTexture.push_back(new TEXTURE(L"mario_left.png", 4, 1, 4, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new TEXTURE(L"mario_right.png", 4, 1, 4, D3DCOLOR_XRGB(253, 253, 253)));
	 
	_listTexture.push_back(new TEXTURE(L"mario_jump_left.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new TEXTURE(L"mario_jump_right.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));

	_listTexture.push_back(new TEXTURE(L"Conrua2.png", 5, 1, 5, D3DCOLOR_XRGB(255, 255, 255)));
	_listTexture.push_back(new TEXTURE(L"caveman.bmp", 8, 2, 12, D3DCOLOR_XRGB(255, 255, 255)));

	_listTexture.push_back(new TEXTURE(L"Goomba_Left.png", 9, 1, 9, D3DCOLOR_XRGB(255, 255, 255)));
	_listTexture.push_back(new TEXTURE(L"Goomba_Right.png", 9, 1, 9, D3DCOLOR_XRGB(255, 255, 255)));
	_listTexture.push_back(new TEXTURE(L"Turtle_Left.png", 6, 1, 6, D3DCOLOR_XRGB(255, 255, 255)));
	_listTexture.push_back(new TEXTURE(L"Turtle_Right.png", 6, 1, 6, D3DCOLOR_XRGB(255, 255, 255)));*/

	/*_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\wallred.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\mario_left.png", 4, 1, 4, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\mario_right.png", 4, 1, 4, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\mario_jump_left.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\mario_jump_right.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\mario.png", 5, 2, 10, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\super_mario.png", 5, 2, 10, D3DCOLOR_XRGB(253, 253, 253)));*/
	
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\PlayNho.png", 6, 2, 12, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Basic.png", 4, 4, 16, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Gach.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Goomba.png", 11, 2, 22, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\item.png", 4, 2, 8, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Land.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Cloud.png", 2, 1, 2, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Grass.png", 2, 1, 2, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Mountain.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\stone.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Pipe.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Star.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\mushroom.png", 2, 1, 2, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Pirhana.png", 2, 1, 2, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Pirhana_32.png", 2, 1, 2, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\numnho.png", 3, 1, 3, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Number.bmp", 10, 1, 10, D3DCOLOR_XRGB(255, 0, 255)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Score.png", 10, 1, 10, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\CoinInfo.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\mariotext.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Brick.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Goomba_32.png", 11, 2, 22, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\expBrick.png", 2, 1, 2, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Brick_32.png", 2, 3, 6, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\item_32.png", 4, 2, 8, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\turtle.png", 6, 2, 12, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Bullet.png", 4, 2, 8, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\Pipengang.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));

	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\infomario.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\infocoin.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\infoworld.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\inforesult.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\infotime.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));

	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\MarioSmall.png", 6, 2, 12, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\MarioBig.png", 5, 2, 10, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\MarioBullet.png", 5, 2, 10, D3DCOLOR_XRGB(253, 253, 253)));
	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\MarioSmall2.png", 6, 2, 12, D3DCOLOR_XRGB(253, 253, 253)));

	_listTexture.push_back(new Texture(d3ddv, L"..\\Resources\\Images\\checkpoint.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
}


/**--------------------------------------------------------
*Description : Destructor
*Method name : ~ResourceMng
*Parameters :   
*Return value :
--------------------------------------------------------**/
ResourceMng::~ResourceMng(void)
{
	_listSurface.clear();
	_listTexture.clear();
}


/**--------------------------------------------------------
*Description : Lay texture
*Method name : GetTexture
*Parameters :   LPWSTR fileName
*Return value : *TEXTURE
--------------------------------------------------------**/
Texture* ResourceMng::GetTexture(LPWSTR fileName)
{
	int size = _listTexture.size();
	Texture* tt;

	for(int i = 0 ; i < size; ++i){
		tt = _listTexture[i];

		if(tt->fileName == fileName){
			return tt;
		}
	}

	//GLMessage(L"Can not GetTexture");
	return NULL;
}


/**--------------------------------------------------------
*Description : Lay surface
*Method name : GetSurface
*Parameters :   LPWSTR fileName
*Return value : *SURFACE
--------------------------------------------------------**/
SURFACE* ResourceMng::GetSurface(LPWSTR fileName){
	int size = _listSurface.size();
	SURFACE* sf;

	for(int i = 0 ; i < size; ++i){
		sf = _listSurface[i];

		if(sf->FileName == fileName){
			return sf;
		}
	}

	//GLMessage(L"Can not GetSurface");
	return NULL;
}


/**--------------------------------------------------------
*Description : Lay doi tuong Resource
*Method name : GetInst
*Parameters :    
*Return value : *ResourceMng
--------------------------------------------------------**/
ResourceMng* ResourceMng::GetInst(LPDIRECT3DDEVICE9 D3ddv, LPDIRECT3DSURFACE9 BackBuffer){
	if(_instance == NULL){
		_instance = new ResourceMng(D3ddv, BackBuffer);
	}

	return _instance;
}
